#include "JWorkingCopiesBaseFile.h"
#include "JWorkingCopiesFile.h"


JWorkingCopiesBaseFile::JWorkingCopiesBaseFile(JWorkingCopiesFileOperation _operate,int _lastChangeVersion,
                int _version,std::string _author,std::string _fullFileName,int _dirOrFile)
                : operate(_operate),lastChangeVersion(_lastChangeVersion),version(_version),
        author(_author),fullFileName(_fullFileName),dirOrFile(_dirOrFile)
{
	 
}

JWorkingCopiesBaseFile::JWorkingCopiesBaseFile()
{
    
}

JWorkingCopiesBaseFile::~JWorkingCopiesBaseFile(void)
{
}

int JWorkingCopiesBaseFile::Serialize( std::iostream& _strea ,int& allSize)
{
	//JWorkingCopiesFileOperation operate;
	//int lastChangeVersion;
	//int version;
	//std::string author;
	//std::string fullFileName;
	//int dirOrFile;
	int classSize = 0,selfSize = 0;
	JSerialize::PutInt(_strea,classSize,selfSize);
	JSerialize::Serialize(_strea,this->operate,classSize);
	JSerialize::Serialize(_strea,this->lastChangeVersion,classSize);
	JSerialize::Serialize(_strea,this->version,classSize);
	JSerialize::Serialize(_strea,this->author,classSize);
	JSerialize::Serialize(_strea,this->fullFileName,classSize);
	JSerialize::Serialize(_strea,this->dirOrFile,classSize);
	selfSize += classSize;
	JSerialize::Verify(_strea,classSize,-1*selfSize);
	allSize += selfSize;
	return selfSize;
}

void JWorkingCopiesBaseFile::ReSerialize( std::iostream& _strea )
{
	int classSize = JSerialize::GetInt(_strea,sizeof(int));
	this->operate = JWorkingCopiesFileOperation(JSerialize::ReSerializeInt(_strea));
	this->lastChangeVersion = JSerialize::ReSerializeInt(_strea);
	this->version = JSerialize::ReSerializeInt(_strea);
	this->author = JSerialize::ReSerializeString(_strea);
	this->fullFileName = JSerialize::ReSerializeString(_strea);
	this->dirOrFile = JSerialize::ReSerializeInt(_strea);
}

//int JWorkingCopiesBaseFile::EnumtoInt( JWorkingCopiesFileOperation _operate )
//{
//	switch(_operate)
//	{
//	case JWorkingFileAdd:
//		return 0;
//	case JWorkingFileDelete:
//		return 1;
//	default:
//		return 2;
//	}
//}

bool JWorkingCopiesBaseFile::operator==( const JWorkingCopiesBaseFile& _file )
{
	if(this->fullFileName == _file.fullFileName)
	{
		return true;
	}
	return false;
}

std::string JWorkingCopiesBaseFile::FileOperationToString( JWorkingCopiesFileOperation operation )
{
	switch(operation)
	{
	case JWorkingFileAdd:
		return "Add";
	case JWorkingFileDelete:
		return "Delete";
	case JWorkingFileNoStatus:
		return "NoStatus";
	case JWorkingFileNotExist:
		return "NotExist";
	default:
		return "Unknow";
	}
}
